﻿package displays.coms 
{
	import debugs.Debug;
	import displays.Sprites.word;
	import flash.display.Sprite;
	import net.netvars;
	import infos.LRCinfo;
	import infos.triggerInfo;
	/**
	 * ...
	 * @author keys_star@163.com
	 */
	public class LRCplayer extends Sprite
	{
		private var iword:word;
		private var ID:uint = 0;
		private var type:String = "new";
		public function LRCplayer() 
		{
			ID = 0;
		}
		public function init():void {
			Debug.send(this + ".init");
			ID = 0;
		}
		public function setWord(s:String):void {
			try{removeChild(iword)}catch(e:Error){}
			iword = new word;
			iword.text = s;
			addChild(iword);
		}
		public function moveTo(id:uint, s:Number):void {
			iword.moveToId(id, s);
		}
		public function nextTime():void {
			Debug.send(this + ".nextID: " + ID);
			getNext(ID);
			ID += 1;
		}
		private function getNext(id:uint) {
			Debug.send(this + " .ID: "+id);
			type = "new";
			var LrcItem:Array = netvars.getVar("LrcItem");
			var aid:uint = 0;
			for (var i = 0; i < LrcItem.length; i++ ) {
				var lrcInfo:LRCinfo = LrcItem[i];
				if (aid == id) {
					Debug.send(this + ".lrcInfo.time: " + lrcInfo.startTime+" .ID: "+id);
					setWord(lrcInfo.lrc);
					type = "new";
					return;
				}
				aid += 1;
				for (var j = 0; j < lrcInfo.tirgger.length; j++ ) {
					var tirggInfo:triggerInfo = lrcInfo.tirgger[j];
					if (aid == id) {
						moveTo(tirggInfo.id, tirggInfo.duration);
						Debug.send(this + ".tirgger.time: " + tirggInfo.startTime+" .ID: "+id);
						type = "old";
						return;
					}
					aid += 1;
				}
			}
		}
	}
}